﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Note.cs" company="HelloWorld">
//   BY苏宣
// </copyright>
// <summary>
//   Defines the Note type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace WindowsFormsApp2.Form
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    /// <summary>
    /// The note.
    /// </summary>
    public partial class Note : Form
    {
        /// <summary>
        /// The save path.
        /// </summary>
        private readonly string savePath;

        /// <summary>
        /// Initializes a new instance of the <see cref="Note"/> class.
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        public Note(string path)
        {
            this.InitializeComponent();
            this.savePath = path;
        }

        /// <summary>
        /// The save_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void Save_Click(object sender, EventArgs e)
        {
            if (this.toolStripTextBox1.Text == string.Empty)
            {
                MessageBox.Show(@"请输入文件名");
                return;
            }

            var fileName = this.savePath + "\\笔记\\" + this.toolStripTextBox1.Text + ".rtf";
            this.richTextBox1.SaveFile(fileName, RichTextBoxStreamType.RichText);

            // MessageBox.Show(fileName);
            this.DialogResult = DialogResult.OK;
        }

        /// <summary>
        /// The bold_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void Bold_Click(object sender, EventArgs e)
        {
            this.fontDialog1.ShowDialog();
            this.richTextBox1.SelectionFont = this.fontDialog1.Font;
        }

        /// <summary>
        /// The tool strip label 1_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ToolStripLabel1_Click(object sender, EventArgs e)
        {
            this.colorDialog1.ShowDialog();
            this.richTextBox1.SelectionColor = this.colorDialog1.Color;
        }

        /// <summary>
        /// The pictures_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void Pics_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.Filter = @"图片文件|*.jpg|所有文件|*.*";
            if (this.openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Clipboard.SetDataObject(Image.FromFile(this.openFileDialog1.FileName), false);
            this.richTextBox1.Paste();
        }
    }
}
